import { IModalData, IOpenViewUtil, ViewMode } from "@ibiz-template/runtime";
import { currentRoute, generateRoutePath } from "../route/route";

/**
 * 打开视图方式工具类
 *
 * @export
 * @class OpenViewUtil
 * @implements {IOpenViewUtil}
 */
export class OpenViewUtil implements IOpenViewUtil {
  /**
   * 直接路径打开视图
   *
   * @param {string} path
   * @return {*}  {Promise<IModalData>}
   * @memberof OpenViewUtil
   */
  push(path: string): Promise<IModalData> {
    throw new Error("Method not implemented.");
  }

  /**
   * 路由打开视图
   *
   * @param {string} appViewId
   * @param {IContext} context
   * @param {(IParams | undefined)} [params]
   * @param {IData} [opts={}]
   * @return {*}  {Promise<IModalData>}
   * @memberof OpenViewUtil
   */
  async root(
    appViewId: string,
    context: IContext,
    params?: IParams | undefined,
    opts: IData = {}
  ): Promise<IModalData> {
    const appView = await ibiz.hub.config.view.get(appViewId!);
    const route = currentRoute();
    const { path } = await generateRoutePath(appView, route, context, params);
    if (opts.routeMode === ViewMode.EMBED) {
      uni.$emit("openView", { fullPath: path });
    } else {
      uni.navigateTo({
        url: path,
      });
    }
    return { ok: true };
  }

  /**
   * 路由模态打开视图
   *
   * @param {string} appViewId
   * @param {IContext} context
   * @param {IParams} [params]
   * @return {*}  {Promise<IModalData>}
   * @memberof OpenViewUtil
   */
  async rootByModal(
    appViewId: string,
    context: IContext,
    params?: IParams
  ): Promise<IModalData> {
    throw new Error("Method not implemented.");
  }

  /**
   * 模态打开视图
   *
   * @param {string} appViewId
   * @param {IContext} context
   * @param {IParams} [params]
   * @return {*}  {Promise<IModalData>}
   * @memberof OpenViewUtil
   */
  async modal(
    appViewId: string,
    context: IContext,
    params?: IParams
  ): Promise<IModalData> {
    throw new Error("Method not implemented.");
  }

  /**
   * 气泡模式打开视图
   *
   * @param {string} appViewId
   * @param {MouseEvent} event
   * @param {IContext} context
   * @param {IParams} [params]
   * @return {*}  {Promise<IModalData>}
   * @memberof OpenViewUtil
   */
  async popover(
    appViewId: string,
    event: MouseEvent,
    context: IContext,
    params?: IParams
  ): Promise<IModalData> {
    throw new Error("Method not implemented.");
  }

  /**
   * 抽屉打开视图
   *
   * @param {string} appViewId
   * @param {IContext} context
   * @param {IParams} [params]
   * @return {*}  {Promise<IModalData>}
   * @memberof OpenViewUtil
   */
  async drawer(
    appViewId: string,
    context: IContext,
    params?: IParams
  ): Promise<IModalData> {
    throw new Error("Method not implemented.");
  }

  /**
   * 自定义打开视图
   *
   * @param {string} appViewId
   * @param {IContext} context
   * @param {IParams} [params]
   * @return {*}  {Promise<IModalData>}
   * @memberof OpenViewUtil
   */
  async custom(
    appViewId: string,
    context: IContext,
    params?: IParams
  ): Promise<IModalData> {
    throw new Error("Method not implemented.");
  }

  /**
   * 独立程序打开视图
   *
   * @param {string} appViewId
   * @param {IContext} context
   * @param {IParams} [params]
   * @return {*}  {Promise<void>}
   * @memberof OpenViewUtil
   */
  async popupApp(
    appViewId: string,
    context: IContext,
    params?: IParams
  ): Promise<void> {
    throw new Error("Method not implemented.");
  }
}
